#ifndef PROTECTEDMEMORY_H
#define PROTECTEDMEMORY_H

//----------------------------------------------------------------------------
// PM_LOCAL_PROTECTION and PM_GLOBAL_PROTECTION are reserved for internal use.
//
#undef PM_LOCAL_PROTECTION
#undef PM_GLOBAL_PROTECTION

//----------------------------------------------------------------------------
// Debug mode compilations alway enable this class for localized testing.
// Global testing should be managed via the .dsp (define PM_PROTECTALLMEMORY).
//
#if defined(_DEBUG)
#  define PM_LOCAL_PROTECTION
#  if defined(PM_PROTECTALLMEMORY)
#    define PM_GLOBAL_PROTECTION
#  endif
#endif

//----------------------------------------------------------------------------
// Release mode compilations enable this class only when the following code
// is manually enabled - which should be infrequent!  Ideally, this should
// only be enabled during the first half of quality assurance testing, so
// buffer overruns can quickly be detected.
//
//              Manual Enable Flag
//                      |
//                      v
#if defined(_NDEBUG) && 0
#  define PM_LOCAL_PROTECTION
#  define PM_GLOBAL_PROTECTION
#endif

//----------------------------------------------------------------------------
// Make sure release mode compilations *know* ProtectedMemory is enabled.
// See comment above if you don't know what this means.
//
#if defined(_NDEBUG) && defined(PM_GLOBAL_PROTECTION)
#  pragma revisit("======================================================")
#  pragma revisit("ProtectedMemory is currently enabled for RELEASE mode.")
#  pragma revisit("    This is probably bad unless this is an eary build ")
#  pragma revisit("    of Casino 3.0.0 (disable on/or before 11-12-2004).")
#  pragma revisit("======================================================")
#endif


//----------------------------------------------------------------------------
// Local protection.
//
#if defined(PM_LOCAL_PROTECTION)
class ProtectedMemory
{
	public:
		static void *	protected_malloc(size_t size);
		static void		protected_free(void * memory);

	private:
		struct Head;

	// prohibited
	private:
		ProtectedMemory();
		ProtectedMemory(ProtectedMemory &);
		ProtectedMemory & operator=(ProtectedMemory &);

};
#endif


//----------------------------------------------------------------------------
// Global protection.
// Warning: Use these global routines ONLY on systems with LOTS of memory!
//
#ifdef PM_GLOBAL_PROTECTION
#include <new>
void * __cdecl	operator new(size_t size) _THROW1(std::bad_alloc);
void * __cdecl	operator new(size_t size, const std::nothrow_t &);
void * __cdecl	operator new[](size_t size) _THROW1(std::bad_alloc);
void * __cdecl	operator new[](size_t size, const std::nothrow_t &);
void __cdecl	operator delete(void * ptr) _THROW0();
void __cdecl	operator delete[](void * ptr) _THROW0();
void * __cdecl malloc(size_t size);
void __cdecl free(void * ptr);
#pragma revisit("ProtectedMemory is missing calloc() and realloc().")
#endif


#endif
